﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Zero.UControl.Base.Enums;

namespace Zero.UControl.Component
{
    public class Message : ContentControl
    {
        public int Time { get; set; }

        [Bindable(true)]
        public MessageType MessageType
        {
            get { return (MessageType)GetValue(MessageTypeProperty); }
            set { SetValue(MessageTypeProperty, value); }
        }

        public static readonly DependencyProperty MessageTypeProperty =
                DependencyProperty.Register("MessageType", typeof(MessageType), typeof(Message), new PropertyMetadata(default(MessageType)));

        public Message()
        {
            Loaded += Message_Loaded;
        }

        private async void Message_Loaded(object sender, RoutedEventArgs e)
        {
            if (Parent is MessageHost host)
            {
                await Task.Delay(Time);
                host.Items.Remove(this);
            }
        }
    }
}
